//
//  Status.swift
//  Weibo
//
//  Created by 孙明海 on 16/1/27.
//  Copyright © 2016年 孙明海. All rights reserved.
//

import UIKit

class Status: NSObject {
    //微博ID
    var id: Int = 0
    //微博信息内容
    var text: String?

    
    //微博来源
    var source: String? {
        didSet {
            print(source)
            source = source?.href()?.text
            print(source)
        }
    }
    //微博创建时间
    var created_at: String?
    
    
    
    var dateTime: String? {
        return NSDate.sinaDate(created_at ?? "")?.dateDescriptinon
    }
    //用户模型
    var user: User?
    //微博配图
    var pic_urls: [[String: String]]?
    
    /// 转发微博的信息字段
    var retweeted_status: Status?
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            user = User(dict: (value as? [String: AnyObject])!)
            return
        }
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = Status(dict: dict)
            }
            return
        }
        
        super.setValue(value, forKey: key)
    }
    override var description: String {
        let keys = ["id", "text", "source", "user","created_at", "retweeted_status"]
        return dictionaryWithValuesForKeys(keys).description
    }
}
